package com.om.authing.event;

import com.om.authing.model.EventLog;
import com.om.common.CommonObject;
import org.codehaus.jackson.map.DeserializationConfig;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;


public class AppEvent extends CommonObject implements Serializable {
    public EventLog parseBody(EventLog eventLog) {
        return eventLog;
    }

    public EventLog checkLog(String line) {
        EventLog eventLog = null;
        try {
            objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
            eventLog = objectMapper.readValue(line, EventLog.class);
            checkTimeFormat(eventLog.getOperationTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return eventLog;
    }

    private void checkTimeFormat(String timeStr) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
        simpleDateFormat.parse(timeStr);
    }
}
